home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / db4less3.arc / TRANPROC.PRG < prev    next >
Text File  |  1990-06-16  |  1KB  |  50 lines

  1. * TRANPROC.PRG
  2. * Example of Transaction Processing
  3. *
  4. * Also: Procedure, On Error, LKSYS(), Set Reprocess
  5.  
  6.  
  7. SET REPROCESS TO 10    && Try network locks 10 times before error
  8. ON ERROR DO errproc    && Procedure errproc handles ROLLBACK
  9. fileok=.T.
  10. USE emp
  11. IF fileok
  12.  BEGIN TRANSACTION     && Begin transaction logging
  13.    REPLACE ALL lname WITH 'BRUCE' FOR lname = 'Bruce' && ERROR IF LOCKED
  14.    LIST LNAME
  15.    WAIT 
  16.  END TRANSACTION       && End transaction logging and update
  17.  LIST LNAME
  18. ENDIF 
  19. ON ERROR               && Reset error handling
  20. RETURN
  21.  
  22. PROCEDURE ERRPROC
  23. MANS='N'
  24. CLEAR
  25. DO CASE
  26. CASE ERROR() = 108     && File locked
  27.  otheruser=IIF(LEN(LKSYS(2))=0,'another',LKSYS(2)) && if no user name
  28.  WAIT 'File is locked by '+TRIM(otheruser)+'. Press any key.'
  29.  fileok=.F.
  30.  RETURN
  31. CASE ERROR() = 109    && Record locked
  32.  otheruser=IIF(LEN(LKSYS(2))=0,'another',LKSYS(2)) && if no user name
  33.  WAIT 'Record is locked by '+TRIM(otheruser)+'. Press any key.'
  34. OTHERWISE             && Any other error
  35.  @ 1,0 SAY MESSAGE()+' '+STR(ERROR(),4)
  36. ENDCASE
  37. @ 2,0 SAY 'DO YOU WISH TO RETRY? ' GET MANS FUNCTION '!'
  38. READ
  39. IF MANS='Y'           && Retry 
  40.  CLEAR
  41.  RETRY
  42. ELSE                  && Rollback
  43.  CLEAR
  44.  @ 0,0 SAY 'ROLLING BACK YOUR CURRENT TRANSACTIONS...'
  45.  ROLLBACK
  46. ENDIF
  47. RETURN
  48.  
  49. * EOP: TRANPROC.PRG
  50.